package com.css.Thread;
//死锁
public class DeadLock {
    public static void main(String[] args) {
        MakeUp makeUp=new MakeUp(0,"css");
        MakeUp makeUp1=new MakeUp(1,"dd");
        makeUp.start();
        makeUp1.start();

    }
}
class Lipstic{

}

class Mirror{

}

class MakeUp extends Thread{
    static Lipstic lipstic=new Lipstic();
    static Mirror mirror=new Mirror();
    int choice;
    String girlName;
   public MakeUp(int choice,String girlName){
       this.choice=choice;
       this.girlName=girlName;
   }
    @Override
    public void run() {
        if(choice==0){
            synchronized (mirror){
                System.out.println(this.girlName+"获得了镜子");
            }
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lipstic){
                System.out.println(this.girlName+"获得了口红");
            }
        }else {
            synchronized (lipstic){
                System.out.println(this.girlName+"获得了口红");
            }
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (mirror){
                System.out.println(this.girlName+"获得了镜子");
            }

        }
    }
}
